package com.vhall.component.controller.room;

import com.vhall.component.controller.room.facade.RoomApiFacade;
import com.vhall.component.entity.room.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.ApiSignatureAuth;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.plugin.common.enums.OperateTypeEnum;
import com.vhall.component.plugin.common.support.Token;
import com.vhall.component.plugin.common.support.TokenThreadLocal;
import com.vhall.component.service.annotation.OperateLog;
import com.vhall.component.service.room.RoomConsoleService;
import com.vhall.component.service.room.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @author guoxin.wang
 * @date 2021/7/12 17:30
 */
@Slf4j
@VhallComponent
public class RoomApiController implements RoomApiFacade {

    @Autowired
    private RoomService roomService;

    @Autowired
    private RoomConsoleService roomConsoleService;

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public RoomAttrRespVO getAttributes(RoomAttrVO reqVO) {
        return roomService.getAttributes(reqVO);
    }

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public Boolean startLive(StartLiveVO reqVO) {
        return roomService.startLive(reqVO);
    }

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public Boolean endLive(EndLiveVO reqVO) {
        return roomService.endLive(reqVO);
    }

    @ApiSignatureAuth
    @TokenAuth
    @Override
    @OperateLog(module = "App-房间管理", type = OperateTypeEnum.CREATE, name = "创建")
    public RoomRespVO create(AppRoomVO reqVO) {
        CreateRoomVO newReqVO = new CreateRoomVO();
        BeanUtils.copyProperties(reqVO, newReqVO);
        return roomConsoleService.create(newReqVO, reqVO.getImage());
    }

    @ApiSignatureAuth
    @TokenAuth
    @Override
    public AppRoomListRespVO list(AppRoomListReqVO reqVO) {
        Token token = TokenThreadLocal.getToken();
        return roomConsoleService.listForApp(token.getAccountId(), reqVO);
    }

    @ApiSignatureAuth
    @TokenAuth
    @Override
    public Boolean update(AppRoomVO reqVO) {
        CreateRoomVO vo = new CreateRoomVO();
        BeanUtils.copyProperties(reqVO, vo);
        return roomConsoleService.update(vo, reqVO.getImage(), reqVO.getChangeimg() != 0);
    }

    @ApiSignatureAuth
    @TokenAuth
    @Override
    public Map<String, Object> getOnlineCheck(OnlineCheckVO reqVO) {
        return roomConsoleService.getOnlineCheck(reqVO);
    }

    @Override
    @TokenAuth
    public IntroductionDetailRspVO detail(IntroductionDetailReqVO introductionDetailReqVO) {
        return roomConsoleService.detail(introductionDetailReqVO);
    }
}
